#import "GKCover.h"
#import "dfhgwhruebvhrheymournrural.h"
#import "dfhgwhruebvhrheygeneralizeignore.h"
#import "dfhgwhruebvhrheyspotfaint.h"
#import "dfhgwhruebvhrheyoutwarddelegate.h"
#import "dfhgwhruebvhrheyluggagerecorder.h"
#import "dfhgwhruebvhrheydelegatelimp.h"
#import "dfhgwhruebvhrheydairyinvest.h"
#import "dfhgwhruebvhrheymagnificenttunnel.h"
#import "dfhgwhruebvhrheymunicipalautomobile.h"
#import "dfhgwhruebvhrheycountermanner.h"
#import "dfhgwhruebvhrheytragedymotivateViewController.h"
#import "dfhgwhruebvhrheyroomcatalogViewController.h"
#import "dfhgwhruebvhrheysemesterfuriousViewController.h"
#import "dfhgwhruebvhrheytransportmortalViewController.h"
@interface dfhgwhruebvhrheytransportmortalViewController ()<dhgfywegwygeydwdefinitelyleak>
@property (nonatomic, copy) NSString *passwd;
@property (nonatomic, assign) BOOL autoSendSms;
@property (nonatomic, strong) dfhgwhruebvhrheymournrural *timer;
@property (nonatomic, strong) dfhgwhruebvhrheygeneralizeignore *codeView;
@property (nonatomic, strong) dfhgwhruebvhrheycountermanner *checkDevicePopView;
@end
@implementation dfhgwhruebvhrheytransportmortalViewController {
	int cutdown;
	UIView *infoView;
	UILabel *amountLabel;
	UILabel *amount;
	UIView *line;
	UILabel *dateLabel;
	UILabel *date;
	UILabel *passwdLabel;
	UIView *captchaView;
	UIButton *forgetPasswdBtn;
	UILabel *tipsLabel;
	UIButton *loanBtn;
}
- (dfhgwhruebvhrheymournrural *)timer {
	if (_timer == nil) {
		_timer = [[dfhgwhruebvhrheymournrural alloc] init];
	}
	return _timer;
}
- (void)viewDidLoad {
	[super viewDidLoad];
	[self loadUI];
}
- (void)loadUI {
	self.autoSendSms = YES;
	self.backgroundColor = [UIColor whiteColor];
	self.navigationStyle = dhgfywegwygeydwreciprocaltransport;
	infoView = [[UIView alloc] init];
	infoView.layer.cornerRadius = 10;
	[self.containerView addSubview:infoView];
	infoView.backgroundColor = @"#EEF3F9".dhgfywegwygeydwlearneddesignate;
	amountLabel = [[UILabel alloc] init];
	amountLabel.text = @"Loan Amount";
	amountLabel.textColor = @"#3B414B".dhgfywegwygeydwlearneddesignate;
	amountLabel.font = [UIFont semiBold:15];
	[infoView addSubview:amountLabel];
	amount = [[UILabel alloc] init];
	NSString *amountString = self.selectedAmount.amount.dhgfywegwygeydwlocalitylearned;
	amount.text = [NSString stringWithFormat:@"PHP %@", amountString];
	amount.textColor = primary_color.dhgfywegwygeydwlearneddesignate;
	amount.font = [UIFont semiBold:15];
	[infoView addSubview:amount];
	line = [[UIView alloc] init];
	[infoView addSubview:line];
	dateLabel = [[UILabel alloc] init];
	dateLabel.text = @"Repayment Date";
	dateLabel.textColor = @"#3B414B".dhgfywegwygeydwlearneddesignate;
	dateLabel.font = [UIFont semiBold:15];
	[infoView addSubview:dateLabel];
	NSInteger time = [[NSUserDefaults standardUserDefaults] integerForKey:dhgfywegwygeydwdiagramregardless];
	NSInteger term = [self.seletedTerm.days integerValue];
	NSInteger seconds = time + term * 24 * 60 *60;
	date = [[UILabel alloc] init];
	date.text = [dfhgwhruebvhrheyoptionsaving formatTime:seconds WithDateFormat:@"MM/dd/yyyy"];
	date.textColor = primary_color.dhgfywegwygeydwlearneddesignate;
	date.font = [UIFont semiBold:15];
	[infoView addSubview:date];
	passwdLabel = [[UILabel alloc] init];
	passwdLabel.text = @"Please enter the registration password";
	passwdLabel.textColor = @"#3B414B".dhgfywegwygeydwlearneddesignate;
	passwdLabel.textAlignment = NSTextAlignmentCenter;
	passwdLabel.font = [UIFont semiBold:15];
	[self.containerView addSubview:passwdLabel];
	captchaView = [[UIView alloc] init];
	[self.containerView addSubview:captchaView];
	self.codeView = [[dfhgwhruebvhrheygeneralizeignore alloc] initWithCount:6 margin:20.0];
	self.codeView.backgroundColor = [UIColor clearColor];
	self.codeView.codeTextColor = primary_color.dhgfywegwygeydwlearneddesignate;
	self.codeView.underLineColor = @"#AAAAAA".dhgfywegwygeydwlearneddesignate;
	self.codeView.delegate = self;
	[captchaView addSubview:self.codeView];
	forgetPasswdBtn = [UIButton buttonWithType:UIButtonTypeCustom];
	forgetPasswdBtn.titleLabel.font = [UIFont regular:12];
	[forgetPasswdBtn setTitle:@"Forgot Password?" forState:UIControlStateNormal];
	[forgetPasswdBtn setTitleColor:@"#FB3314".dhgfywegwygeydwlearneddesignate forState:UIControlStateNormal];
	[self.containerView addSubview:forgetPasswdBtn];
	[forgetPasswdBtn addTarget:self action:@selector(forgetPasswdBtnAction) forControlEvents:UIControlEventTouchUpInside];
	tipsLabel = [[UILabel alloc] init];
	tipsLabel.text = @"1. Please note that the withdrawal method will not be change after select it. \n2. Other unofficial repayment channels are not acceptable to avoid being frauded. \n3. If you pay the loan on time,you will enjoy the audit exemption period.If you are several days overdue,your next loan limit may reduced to the minimum.";
	tipsLabel.numberOfLines = 0;
	tipsLabel.font = [UIFont regular:14];
	tipsLabel.textColor = @"#AAAAAA".dhgfywegwygeydwlearneddesignate;
	[self.containerView addSubview:tipsLabel];
	loanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
	loanBtn.backgroundColor = primary_color.dhgfywegwygeydwlearneddesignate;
	loanBtn.titleLabel.font = [UIFont semiBold:18];
	loanBtn.layer.cornerRadius = 10;
	[loanBtn setTitle:@"Get Loan" forState:UIControlStateNormal];
	[loanBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
	[loanBtn addTarget:self action:@selector(loanBtnAction) forControlEvents:UIControlEventTouchUpInside];
	[self.containerView addSubview:loanBtn];
}
- (void)startTimer {
	__weak typeof(self) weakSelf = self;
	[self.timer startWithAction:^{
		__strong typeof(weakSelf) strongSelf = weakSelf;
		dispatch_async(dispatch_get_main_queue(), ^{
			[strongSelf updateTimer];
		});
	}];
}
- (void)updateTimer {
	if (cutdown <= 0) {
		cutdown = dhgfywegwygeydwleakconceal;
		if (_timer) {
			[_timer cancel];
			_timer = nil;
		}
		self.checkDevicePopView.sendBtn.userInteractionEnabled = YES;
		self.checkDevicePopView.sendBtn.backgroundColor = primary_color.dhgfywegwygeydwlearneddesignate;
		[self.checkDevicePopView.sendBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
		[self.checkDevicePopView.sendBtn setTitle:@"Send" forState:UIControlStateNormal];
	}else {
		self.checkDevicePopView.sendBtn.userInteractionEnabled = NO;
		self.checkDevicePopView.sendBtn.backgroundColor = @"#EEEEEE".dhgfywegwygeydwlearneddesignate;
		[self.checkDevicePopView.sendBtn setTitleColor:@"#AAAAAA".dhgfywegwygeydwlearneddesignate forState:UIControlStateNormal];
		[self.checkDevicePopView.sendBtn setTitle:[NSString stringWithFormat:@"%02ds", cutdown] forState:UIControlStateNormal];
		cutdown -= 1;
	}
}
- (void)sendSms {
		NSMutableDictionary *params = [NSMutableDictionary dictionary];
		params[@"tel_number"] = [dfhgwhruebvhrheyoptionsaving getUserData].phone;
		[dfhgwhruebvhrheyoptionsaving.keyWindow startLoading];
		__weak typeof(self) weakSelf = self;
		[[dfhgwhruebvhrheyluggagerecorder shareInstance] dhgfywegwygeydwbarrierawait:dhgfywegwygeydwawaitlamb path:sendLoanSmsApi isEncrypt:YES withParams:params success:^(NSURLSessionDataTask * _Nonnull task, NSString * _Nonnull json) {
			__strong typeof(weakSelf) strongSelf = weakSelf;
			[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
			dfhgwhruebvhrheysternideology *model = [dfhgwhruebvhrheysternideology yy_modelWithJSON:json];
			if (model.code == 200) {
				[strongSelf startTimer];
			}else {
				[dfhgwhruebvhrheyoptionsaving.keyWindow show:model.error];
			}
		} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
			[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
		}];
}
- (void)showLoanSmsPopView {
	__weak typeof(self) weakSelf = self;
	if (self.autoSendSms) {
		[self sendSms];
	}
	self.autoSendSms = NO;
	cutdown = dhgfywegwygeydwleakconceal;
	self.checkDevicePopView = [[NSBundle mainBundle] loadNibNamed:@"dfhgwhruebvhrheycountermanner" owner:nil options:nil].firstObject;
	self.checkDevicePopView.frame = CGRectMake(13, 0, dhgfywegwygeydwdispositionvisualize-13*2, 348);
	[GKCover coverFrom:[dfhgwhruebvhrheyoptionsaving keyWindow] contentView:self.checkDevicePopView style:GKCoverStyleTranslucent showStyle:GKCoverShowStyleCenter showAnimStyle:GKCoverShowAnimStyleCenter hideAnimStyle:GKCoverHideAnimStyleCenter notClick:YES];
	[self.checkDevicePopView sureViewBtnsClick:^(UIButton * _Nonnull sender, NSString * _Nonnull code) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		if (sender.tag == 100) {
			[strongSelf sendSms];
		}else {
			[GKCover hideCover];
			[strongSelf getMoney:code];
		}
	}];
}
- (void)loanSuccess {
	__weak typeof(self) weakSelf = self;
	dfhgwhruebvhrheymunicipalautomobile *popView = [[NSBundle mainBundle] loadNibNamed:@"dfhgwhruebvhrheymunicipalautomobile" owner:nil options:nil].firstObject;
	popView.frame = CGRectMake(13, 0, dhgfywegwygeydwdispositionvisualize-13*2, 352);
	[GKCover coverFrom:[dfhgwhruebvhrheyoptionsaving keyWindow] contentView:popView style:GKCoverStyleTranslucent showStyle:GKCoverShowStyleCenter showAnimStyle:GKCoverShowAnimStyleCenter hideAnimStyle:GKCoverHideAnimStyleCenter notClick:YES];
	[popView btnClick:^{
		__strong typeof(weakSelf) strongSelf = weakSelf;
		[GKCover hideCover];
		[strongSelf loadOffLineCode];
	}];
}
- (void)loadOffLineCode {
	if (self.passwd.length != 6) return;
	NSMutableDictionary *params = [NSMutableDictionary dictionary];
	params[@"password"] = self.passwd;
	[dfhgwhruebvhrheyoptionsaving.keyWindow startLoading];
	__weak typeof(self) weakSelf = self;
	[[dfhgwhruebvhrheyluggagerecorder shareInstance] dhgfywegwygeydwbarrierawait:dhgfywegwygeydwawaitlamb path:getOffLineCodeApi isEncrypt:YES withParams:params success:^(NSURLSessionDataTask * _Nonnull task, NSString * _Nonnull json) {
		[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
		__strong typeof(weakSelf) strongSelf = weakSelf;
		dfhgwhruebvhrheymagnificenttunnel *model = [dfhgwhruebvhrheymagnificenttunnel yy_modelWithJSON:json];
		if (model.code == 200) {
			[strongSelf detailOffLinePage:model];
		}else {
			[dfhgwhruebvhrheyoptionsaving.keyWindow show:model.error];
		}
	} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
		[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
	}];
}
- (void)detailOffLinePage:(dfhgwhruebvhrheymagnificenttunnel *)model {
	dfhgwhruebvhrheysemesterfuriousViewController *code = [[dfhgwhruebvhrheysemesterfuriousViewController alloc] init];
	code.codeModel = model;
	[self.navigationController pushViewController:code animated:YES];
}
- (void)getMoney:(nullable NSString *)code {
	NSMutableDictionary *params = [NSMutableDictionary dictionary];
	params[@"user_passwords"] = self.passwd;
	params[@"pro_id"] = self.seletedTerm.info.p_id;
	params[@"price"] = self.selectedAmount.amount;
	params[@"sms_code"] = code;
	params[@"days"] = self.seletedTerm.days;
	params[@"rid"] = self.selectedAmount.rid;
	params[@"riskdata"] = [dfhgwhruebvhrheyoptionsaving getRiskJsonData];
	params[@"tid"] = self.seletedTerm.ud_id;
	params[@"dev_id"] = [dfhgwhruebvhrheyoptionsaving uuid].dhgfywegwygeydwscholarshiptexture;
	[dfhgwhruebvhrheyoptionsaving.keyWindow startLoading];
	__weak typeof(self) weakSelf = self;
	[[dfhgwhruebvhrheyluggagerecorder shareInstance] dhgfywegwygeydwbarrierawait:dhgfywegwygeydwawaitlamb path:getLoanOffLineApi isEncrypt:YES withParams:params success:^(NSURLSessionDataTask * _Nonnull task, NSString * _Nonnull json) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
		dfhgwhruebvhrheydairyinvest *model = [dfhgwhruebvhrheydairyinvest yy_modelWithJSON:json];
		if (model.code == 200) {
			[strongSelf loanSuccess];
			[dfhgwhruebvhrheyoptionsaving uploadRiskDataByCatchId:@"2" andApplyId:model.oid withDetailId:model.deta_id];
		}else {
			[dfhgwhruebvhrheyoptionsaving.keyWindow show:model.error];
		}
	} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
		[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
	}];
}
- (void)loanBtnAction {
	if (self.passwd.length != 6) {
		return [self.view show:@"Please enter the complete password."];
	}
	[dfhgwhruebvhrheyoptionsaving.keyWindow startLoading];
	__weak typeof(self) weakSelf = self;
	[[dfhgwhruebvhrheyluggagerecorder shareInstance] dhgfywegwygeydwbarrierawait:dhgfywegwygeydwawaitlamb path:checkLoanDeviceApi isEncrypt:YES withParams:nil success:^(NSURLSessionDataTask * _Nonnull task, NSString * _Nonnull json) {
		[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
		__strong typeof(weakSelf) strongSelf = weakSelf;
		dfhgwhruebvhrheydelegatelimp *model = [dfhgwhruebvhrheydelegatelimp yy_modelWithJSON:json];
		if (model.code == 200) {
			if (model.code_type == 0) {
				[strongSelf showLoanSmsPopView];
			}else {
				[strongSelf getMoney:nil];
			}
		}else {
			[dfhgwhruebvhrheyoptionsaving.keyWindow show:model.error];
		}
	} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
		[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
	}];
}
- (void)forgetPasswdBtnAction {
    NSLog(@"提款忘记密码");
    dfhgwhruebvhrheytragedymotivateViewController *forgetVC = [[dfhgwhruebvhrheytragedymotivateViewController alloc] init];
    forgetVC.mobile = [dfhgwhruebvhrheyoptionsaving getUserData].phone;
    forgetVC.canNotEditMobile = YES;
    [self.navigationController pushViewController:forgetVC animated:YES];
}
- (void)viewDidLayoutSubviews {
	[super viewDidLayoutSubviews];
	[infoView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(self.containerView).offset(19);
		make.left.equalTo(self.containerView).offset(13);
		make.centerX.equalTo(self.containerView);
		make.height.mas_equalTo(101);
	}];
	[infoView drawBoardWithCornerRadius:10 andColor:primary_color.dhgfywegwygeydwlearneddesignate];
	[amountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(infoView).offset(14);
		make.left.equalTo(infoView).offset(20);
		make.height.mas_equalTo(23);
	}];
	[amount mas_makeConstraints:^(MASConstraintMaker *make) {
		make.right.equalTo(infoView.mas_right).offset(-20);
		make.centerY.equalTo(amountLabel);
	}];
	[line mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.right.equalTo(infoView);
		make.height.mas_equalTo(0.5);
		make.centerY.equalTo(infoView);
	}];
	[line drawDashLine:primary_color.dhgfywegwygeydwlearneddesignate];
	[dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(line.mas_bottom).offset(14);
		make.left.equalTo(amountLabel);
		make.height.mas_equalTo(23);
	}];
	[date mas_makeConstraints:^(MASConstraintMaker *make) {
		make.right.equalTo(amount);
		make.centerY.equalTo(dateLabel);
	}];
	[passwdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(infoView.mas_bottom).offset(20);
		make.centerX.equalTo(self.containerView);
		make.height.mas_equalTo(23);
	}];
	[captchaView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerX.equalTo(self.containerView);
		make.left.equalTo(self.containerView).offset(54);
		make.top.equalTo(passwdLabel.mas_bottom).offset(10);
		make.size.mas_equalTo(CGSizeMake(dhgfywegwygeydwdispositionvisualize-108, 45));
	}];
	[self.codeView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.edges.equalTo(captchaView);
	}];
	[forgetPasswdBtn mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(captchaView.mas_bottom).offset(18);
		make.centerX.equalTo(captchaView);
		make.height.mas_equalTo(17);
	}];
	[tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(forgetPasswdBtn.mas_bottom).offset(30);
		make.left.equalTo(self.containerView).offset(13);
		make.centerX.equalTo(self.containerView);
		make.height.mas_equalTo(160);
	}];
	[loanBtn mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(tipsLabel.mas_bottom).offset(50);
		make.left.centerX.equalTo(tipsLabel);
		make.height.mas_equalTo(50);
		make.bottom.equalTo(self.containerView).offset(-15);
	}];
}
- (void)codeViewDidInputCompleted:(dfhgwhruebvhrheygeneralizeignore *)codeView {
	self.passwd = codeView.code;
}
@end
